import dt from '@dt/dt'
import toolMgr from '@/biz/base/tool.js'
let _this = null

function accessory(info) {
  let api = toolMgr.unloadFile()
  let files = []
  if (info.picUrl && info.picUrl.length > 0) {
    info.picUrl.forEach(item => {
      console.log(item, files, '*****')
      if (item && files.length == 0) {
        files.push({
          name: item.name,
          url: item.url
        })
      }
    })
  }
  return {
    title: '服务信息图片',
    key: 'picUrl',
    uploadImg: {
      title: '服务信息图片',
      api,
      files,
      multiple: false,
      preview: (file) => {
        console.log(file)
        toolMgr.downloadFile(file.url, file.name)
      },
      show: false,
      hideDel: _this.isView ? true : false,
      maxlength: _this.isView ? -1 : 1,
      format: ['jpg', 'jpeg', 'png'],
    },
    data: {
      to: (v) => {
        let picUrl = v.map(item => {
          return {
            name: item.name,
            url: item.response ? item.response.data.imageURL : item.url,
          }
        })
        return {
          picUrl
        }
      }
    },
  }
}

function options(vm) {
  _this = vm
  console.log(_this.info)
  return [
    {
      title: '服务信息标题',
      placeholder: '请输入服务信息内容',
      key: 'serviceTitle',
      disabled: _this.isView,
      col: 17,
      input: { maxlength: 15, showWordLimit: true },
      rules: [{
        required: true,
        message: '服务信息内容不能为空',
        trigger: 'blur'
      }]
    },
    {
      title: '服务信息内容',
      placeholder: '请输入服务信息内容',
      key: 'serviceContent',
      disabled: _this.isView,
      col: 17,
      input: {
        type: 'textarea',
        showWordLimit: true,
        maxlength: 200,
        autosize: {
          minRows: 3,
          maxRows: 5
        }
      }
    },
    accessory(_this.info)
  ]
}
export default {
  options,
}